/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.profesoresparticulares.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.log4j.Logger;
import pe.edu.upc.dew.profesoresparticulares.util.JdbcUtils;

/**
 *
 * @author Wilder
 */
public class ComunDao {

    Logger log = Logger.getLogger(this.getClass());

    public ArrayList<HashMap<String, String>> getLista(String llave) {
        ArrayList<HashMap<String, String>> lista = new ArrayList<HashMap<String, String>>();
        Connection connection = JdbcUtils.getConnection();

        connection = null;
        Statement st = null;
        ResultSet rs = null;

        try {
            connection = JdbcUtils.getConnection();
            st = connection.createStatement();
            final String query = "select * from comun where campo = '"+llave+"'";
            rs = st.executeQuery(query);
            while (rs.next()) {
                HashMap<String, String> m = new HashMap<String, String>();
                m.put("clave",rs.getString("clave"));
                m.put("descripcion",rs.getString("descripcion"));
                lista.add(m);
            }
            return lista;
        } catch (SQLException e) {
            log.error(e.toString());
        } finally {
            JdbcUtils.closeResultSet(rs);
            JdbcUtils.closeStatement(st);
            JdbcUtils.closeConnection(connection);
            return lista;
        }

    }

}
